/**
 *
 * Licensed Materials - Property of IBM 
 * 
 * OCO Source Materials 
 * 
 * (C) Copyright IBM Corp. 2011, 2012 All Rights Reserved 
 * 
 * The source code for this program is not published or other- 
 * wise divested of its trade secrets, irrespective of what has 
 * been deposited with the U.S. Copyright Office. 
 *
 */

/**
 * CHANGE HiSTORY:
 * Author             Time                 Description
 *
 */
package com.ibm.ba.demo.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;

import com.ibm.ba.demo.entity.BaDemoScoreResult;
import com.ibm.ba.demo.entity.Product;

public class BatchScoreResultSetExtractor implements
		ResultSetExtractor<BaDemoScoreResult> {

	/**
	 * Extract score result 
	 */
	@Override
	public BaDemoScoreResult extractData(ResultSet rs) throws SQLException,
			DataAccessException {
		BaDemoScoreResult baDemoScoreResult = new BaDemoScoreResult();
		List<Product> productList = new ArrayList<Product>(); 
		
		while (rs.next()) {
			Product product = new Product();
			baDemoScoreResult.setCustomerId(rs.getInt("B_CUSTKEY"));
			product.setProductId(rs.getInt("B_PARTKEY"));
			product.setProductScore(rs.getBigDecimal("B_SCORE").toString());
			product.setProductName(rs.getString("P_NAME"));
			productList.add(product);
		}
		baDemoScoreResult.setProducts(productList);
		return baDemoScoreResult;
	}

}
